//
//  String+Extension.swift
//  JKWeibo
//
//  Created by albert on 16/5/14.
//  Copyright © 2016年 albert. All rights reserved.
//

import UIKit

extension String {
    /** 缓存路径 */
    func cacheDir() -> String{
        // 1.获取缓存目录路径
        let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomainMask.UserDomainMask, true).last!
        
        // 2.生成路径
        let filePath = (path as NSString).stringByAppendingPathComponent(self)
        JKLog(filePath)
        return filePath
    }
    
    /** 文档路径 */
    func docDir() -> String{
        // 1.获取文档目录路径
        let path = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true).last!
        
        // 2.生成路径
        // 处理带有斜线 / 的情况
        let name = (self as NSString).lastPathComponent
        let filePath = (path as NSString).stringByAppendingPathComponent(name)
        
        return filePath
    }
    
    /** 临时路径 */
    func tmpDir() -> String{
        // 1.获取临时目录路径
        let path = NSTemporaryDirectory()
        
        // 2.生成路径
        let filePath = (path as NSString).stringByAppendingPathComponent(self)
        
        return filePath
    }
}